# #encoding:utf-8
#
from  urllib import request
from http.cookiejar import MozillaCookieJar
#
#cookiejar  = MozillaCookieJar('baidu2.txt')
# cookiejar.load(ignore_discard=True,ignore_expires=True)
# handler = request.HTTPCookieProcessor(cookiejar)
# opener = request.build_opener(handler)
# headers = {
#     "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36",
# }
#
# resp = opener.open("http://httpbin.org/cookies")
# print(resp.read())
# print(cookiejar)
# for cookie in cookiejar:
#     print(cookie)
# # cookiejar.save(ignore_discard=True)

cookiejar  = MozillaCookieJar('baidu2.txt')
handler = request.HTTPCookieProcessor(cookiejar)
opener = request.build_opener(handler)
req = request.Request('http://www.baidu.com')
response = opener.open(req)
cookiejar.save(ignore_discard=True,ignore_expires=True)